import * as constants from './constants';
import { fromJS } from 'immutable'

const defaultState = fromJS({
    focused: false,
    enterInto: false,
    list: [],
    page: 1,
    totalPage: 1
})


export default (state = defaultState, action) => {
    switch (action.type) {
        case constants.SEARCH_FOCUS:
            return state.set('focused', true)
        case constants.SEARCH_BLUR:
            return state.set('focused', false)
        case constants.CHANGE_ENTER:
            return state.set('enterInto', true)
        case constants.CHANGE_LEAVE:
            return state.set('enterInto', false)
        case constants.CHANGE_PAGE:
            return state.set('page', action.page)
        case constants.SEARCH_LIST:
            return state.merge({
                list: action.data,
                totalPage: action.totalPage
            });

        default:
            return state
    }
}